import { request } from '@/service/request';

/** 获取同步状态 */
export function fetchSyncStatus() {
  return request<{
    tasks: string;
    callRecords: string;
    scripts: string;
    tasksLastSuccessTime: number;
    callRecordsLastSuccessTime: number;
    scriptsLastSuccessTime: number;
    tasksLastError: string;
    callRecordsLastError: string;
    scriptsLastError: string;
    tasksLastErrorTime: number;
    callRecordsLastErrorTime: number;
    scriptsLastErrorTime: number;
  }>({
    url: '/outbound/sync/status',
    method: 'get'
  });
}

/** 手动触发同步 */
export function fetchManualSync(type: 'tasks' | 'callRecords' | 'scripts') {
  return request<boolean>({
    url: `/outbound/sync/${type}/manual`,
    method: 'post'
  });
}

/** 同步任务数据 */
export function fetchSyncTasks(taskId?: string) {
  return request<boolean>({
    url: '/outbound/sync/tasks',
    method: 'post',
    params: { taskId }
  });
}

/** 同步通话记录 */
export function fetchSyncCallRecords(taskId?: string) {
  return request<boolean>({
    url: '/outbound/sync/call-records',
    method: 'post',
    params: { taskId }
  });
}

/** 同步剧本数据 */
export function fetchSyncScripts() {
  return request<boolean>({
    url: '/outbound/sync/scripts',
    method: 'post'
  });
}

/** 同步所有数据 */
export function fetchSyncAllData() {
  return request<boolean>({
    url: '/outbound/sync/all',
    method: 'post'
  });
}
